//
//  DCStoresRecommendCell.m
//  商城
//
//  Created by runone02 on 2018/8/29.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "DCStoresRecommendCell.h"
#import "DCBeautyShopItem.h"
#import <UIImageView+WebCache.h>

@interface DCStoresRecommendCell()
@property (strong, nonatomic)  UIImageView *shopImageView;
@property (strong, nonatomic)  UIImageView *yongImageView;
@property (strong, nonatomic)  UILabel *shopTitleLabel;
@property (strong, nonatomic)  UILabel *ghjLabel;
@property (strong, nonatomic)  UILabel *shopMoneyLabel;
/** 上架按钮*/
@property (nonatomic,strong) UIButton *shangjiaBtn;
@end
@implementation DCStoresRecommendCell


- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self setUpAllChildView];
    }
    return self;
}

- (void)setUpAllChildView{
    WEAKSELF
    self.shopImageView = [[UIImageView alloc]init];
    [self.shopImageView setImage:IMAGE(@"default_160")];
    [self addSubview:self.shopImageView];
    [self.shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(10);
        make.left.mas_equalTo(self).with.offset(W_RATIO(15));
        make.right.mas_equalTo(self).with.offset(-W_RATIO(15));
        make.height.mas_equalTo(W_RATIO(240));
    }];
    
    self.shopTitleLabel = [[UILabel alloc]init];
    self.shopTitleLabel.font = TITLE_FONT(24);
    [self addSubview:self.shopTitleLabel];
    [self.shopTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.shopImageView.mas_bottom).with.offset(W_RATIO(20));
        make.left.mas_equalTo(weakSelf.shopImageView);
        make.right.mas_equalTo(weakSelf.shopImageView);
        make.height.mas_equalTo(W_RATIO(20));
    }];
    
    self.yongImageView = [[UIImageView alloc]init];
    [self.yongImageView setImage:IMAGE(@"mshop_commission_icon")];
    [self addSubview:self.yongImageView];
    [self.yongImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.shopImageView);
        make.top.mas_equalTo(weakSelf.shopTitleLabel.mas_bottom).with.offset(W_RATIO(20));
        make.size.mas_equalTo(weakSelf.yongImageView.image.size);
    }];
    
    self.ghjLabel = [[UILabel alloc]init];
    self.ghjLabel.font = TITLE_FONT(24);
    [self addSubview:self.ghjLabel];
    [self.ghjLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.yongImageView);
        make.left.mas_equalTo(weakSelf.yongImageView.mas_right).with.offset(W_RATIO(10));
        make.right.mas_equalTo(self).with.offset(-10);
        make.height.mas_equalTo(weakSelf.yongImageView);
    }];
    
    self.shopMoneyLabel = [[UILabel alloc]init];
    self.shopMoneyLabel.font = TITLE_FONT(28);
    self.shopMoneyLabel.textColor = [UIColor redColor];
    [self addSubview:self.shopMoneyLabel];
    [self.shopMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.shopImageView);
        make.top.mas_equalTo(weakSelf.yongImageView.mas_bottom).with.offset(W_RATIO(20));
        make.right.mas_equalTo(self).with.offset(-10);
        make.height.mas_equalTo(20);
    }];
    
    self.shangjiaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.shangjiaBtn setTitle:@"上架" forState:UIControlStateNormal];
    [self.shangjiaBtn.layer setMasksToBounds:YES];
    [self.shangjiaBtn.layer setCornerRadius:4.0];
    
    [self.shangjiaBtn.layer setBorderWidth:1.0];
    self.shangjiaBtn.layer.borderColor = [UIColor redColor].CGColor;
    

    self.shangjiaBtn.titleLabel.font = TITLE_FONT(30);
    [self.shangjiaBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.shangjiaBtn addTarget:self action:@selector(shelvesButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    self.shangjiaBtn.backgroundColor = [UIColor redColor];
    [self addSubview:self.shangjiaBtn];
    [self.shangjiaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(weakSelf.shopMoneyLabel.mas_bottom).with.offset(W_RATIO(30));
        make.left.mas_equalTo(self).with.offset(10);
        make.right.mas_equalTo(self).with.offset(-10);
    }];
}

- (void)setShopItem:(DCBeautyShopItem *)shopItem{
    _shopItem = shopItem;
    WEAKSELF
    [self.shopImageView sd_setImageWithURL:[NSURL URLWithString:shopItem.shopImageUrl] placeholderImage:[UIImage imageNamed:@"default_160"]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        weakSelf.shopImageView.layer.cornerRadius = 8;
        weakSelf.shopImageView.layer.masksToBounds = YES;
    }];

    self.shopTitleLabel.text = shopItem.shopTitle;
    self.ghjLabel.text = [NSString stringWithFormat:@"%@国美币",shopItem.shopCommission];
    self.shopMoneyLabel.text = [NSString stringWithFormat:@"¥ %@",shopItem.shopAmount];
}

- (void)shelvesButtonClick:(UIButton *)btn {
    if (_shelvesClickBlock) {
        _shelvesClickBlock();
    }
}
@end
